package com.sms.web.domain.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sms.common.persistence.DynamicSpecifications;
import com.sms.common.persistence.SearchFilter;
import com.sms.domain.entity.SmsHistory;
import com.sms.domain.service.SmsHistoryService;
import com.sms.web.domain.dao.SmsHistoryDao;

/**
 * @desc 
 * @author wjw
 * @time 2017年11月16日下午3:33:55
 */
@Service
@Transactional
public class SmsHistoryServiceImpl implements SmsHistoryService {
    
    @Autowired
    private SmsHistoryDao smsHistoryDao;
    
    @Override
    @Transactional(readOnly = true)
    public Page<SmsHistory> findAll(Map<String, Object> searchParams, int pageNumber, int pageSize) {
        
        PageRequest pageRequest = new PageRequest(pageNumber - 1, pageSize, new Sort(Direction.DESC, "smsHistoryId"));
        Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);
        Specification<SmsHistory> spec = DynamicSpecifications.bySearchFilter(filters.values(), SmsHistory.class);
        return smsHistoryDao.findAll(spec, pageRequest);
    }
    
    /**
     * 保存记录
     * @param smsHistory xx
     */
    @Override
    public void save(SmsHistory smsHistory) {
        smsHistoryDao.save(smsHistory);
        
    }
    
}
